<template>
  <!-- <button @click="count++">count is: {{ count }}</button>
   <h1>{{msg.split('')}}</h1> -->

  <div id="student">
    <P class="text_center">获取Code</P>

  </div>


</template>
<script>
import Router from "../router/index";
import axios from "axios";
import { useRoute } from "vue-router";
import {
  onBeforeMount,
  onBeforeUnmount,
  onBeforeUpdate,
  onMounted,
  onUpdated,
  getCurrentInstance,
  ref,
} from "vue";
export default {
  name: "HelloWorld",
  props: {
    msg: String,
    code: "",
  },

  setup(props, ctx) {
    var count = 0;
    var number = 1;
    const getUserInfo = () => {
      var appId = "wxe7a05f228bd548c9";
      var appSercret = "138317db7e3735348a2f16b55e8cf234";
    //  var redirectUrl = "http://test.lwsn95.site/#/about";
     var redirectUrl=encodeURI("http://test.lwsn95.site/#/about");
     debugger;
      var getCodeUrl ="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+redirectUrl+"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
     alert(getCodeUrl);
      sessionStorage.setItem("getCodeUrl",getCodeUrl);
    //  window.location.href = getCodeUrl;
      if (1==2) {
        // const route = useRoute();
        // console.log("当前获取的querycode是" + route.query.code);
        // console.log("当前获取的paramscode是" + route.params.code);

        //要获取用户信息啦
        // axios.get(getCodeUrl).then((res) => {
        //   //debugger;
        //   console.log(res);
        //   // Router.push({ path: "/info", query: { code: 222222 } });
        // });
      }

      // axios({
      //   url: "http://121.4.155.37:452/test",
      //   method: "get"
      // }).then((res) => {

      //     debugger
      //     console.log(res);

      //   });
    };

    onBeforeMount(() => {
      // console.log(el, binding, vnode, prevVnode);
      console.log("onBeforeMount");

      console.log("------------------");
    });
    onMounted(() => {
      const route = useRoute();
      console.log("当前获取的querycode是" + route.query.code);
      console.log("当前获取的paramscode是" + route.params.code);

      console.log("--------======----------");
      getUserInfo();
    });

    onBeforeUpdate(() => {
      console.log("onBeforeUpdate");
      console.log("------------------");
    });
    onUpdated(() => {
      console.log("onUpdated");

      console.log("------------------");
    });

    onBeforeUnmount(() => {
      console.log("onUpdated");
      console.log("------------------");
    });
    onMounted(() => {
      console.log("onMounted");
      console.log("------------------");
    });
    return {
      count,
      number,
    };
  },
  mounted() {
    var dd = this.$route.query.code;
    var pp = this.$route.params;
    //debugger;
  },
};
</script>



